﻿using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Gadgeteer.Interfaces.Fakes.Tests
{
    [TestFixture]
    public class FakeTempratureHumidityTest
    {
        [Test]
        public void Temprature_GetTwoMeasurements_Manual()
        {
            var measurements = new List<double>();

            using (var fake = new FakeTempratureHumidity("fake1"))
            {
                fake.Temperature = 22;
                fake.TemperatureMeasured += (s, e) => measurements.Add(e);

                fake.RequestMeasurement();
                Thread.Sleep(300);
                Assert.That(measurements.ToList(), Is.EquivalentTo(new[] { 22.0 }));

                fake.Temperature = 23;
                fake.RequestMeasurement();
                Thread.Sleep(300);
                Assert.That(measurements.ToList(), Is.EquivalentTo(new[] { 22.0, 23.0 }));
            }
        }

        [Test]
        public void Temprature_GetTwoMeasurements_Continous()
        {
            var measurements = new List<double>();

            using (var fake = new FakeTempratureHumidity("fake1"))
            {
                fake.Temperature = 22;
                fake.TemperatureMeasured += (s, e) => measurements.Add(e);

                fake.StartContinuousMeasurements();
                Thread.Sleep(300);
                Assert.That(measurements.ToList(), Is.EquivalentTo(new[] { 22.0 }));

                fake.Temperature = 23;
                Thread.Sleep(500);
                Assert.That(measurements.ToList(), Is.EquivalentTo(new[] { 22.0, 23.0 }));
            }
        }
    }
}
